package com.ruoyi.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CdCourseTeacher;
import com.ruoyi.course.service.ICdCourseTeacherService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程-教师关联Controller
 * 
 * @author ruoyi
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/course_design/course-teacher")
public class CdCourseTeacherController extends BaseController
{
    @Autowired
    private ICdCourseTeacherService cdCourseTeacherService;

    /**
     * 查询课程-教师关联列表
     */
    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(CdCourseTeacher cdCourseTeacher)
    {
        startPage();
        List<CdCourseTeacher> list = cdCourseTeacherService.selectCdCourseTeacherList(cdCourseTeacher);
        return getDataTable(list);
    }

    /**
     * 导出课程-教师关联列表
     */
    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:export')")
    @Log(title = "课程-教师关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CdCourseTeacher cdCourseTeacher)
    {
        List<CdCourseTeacher> list = cdCourseTeacherService.selectCdCourseTeacherList(cdCourseTeacher);
        ExcelUtil<CdCourseTeacher> util = new ExcelUtil<CdCourseTeacher>(CdCourseTeacher.class);
        util.exportExcel(response, list, "课程-教师关联数据");
    }

//    /**
//     * 获取课程-教师关联详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:query')")
//    @GetMapping(value = "/{teacherId}")
//    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
//    {
//        return success(cdCourseTeacherService.selectCdCourseTeacherByTeacherIdAndCourseId(teacherId));
//    }

    /**
     * 新增课程-教师关联
     */
    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:add')")
    @Log(title = "课程-教师关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CdCourseTeacher cdCourseTeacher)
    {
        return toAjax(cdCourseTeacherService.insertCdCourseTeacher(cdCourseTeacher));
    }

    /**
     * 修改课程-教师关联
     */
    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:edit')")
    @Log(title = "课程-教师关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CdCourseTeacher cdCourseTeacher)
    {
        return toAjax(cdCourseTeacherService.updateCdCourseTeacher(cdCourseTeacher));
    }

    /**
     * 删除课程-教师关联
     */
    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:remove')")
    @Log(title = "课程-教师关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(cdCourseTeacherService.deleteCdCourseTeacherByTeacherIds(teacherIds));
    }

    /**
     * 查询课程-教师指导的课程
     */
    @PreAuthorize("@ss.hasPermi('course_design:course-teacher:list')")
    @GetMapping("/listBySelf")
    public AjaxResult listBySelf()
    {
        List<CdCourseTeacher> list = cdCourseTeacherService.listBySelf();
        return AjaxResult.success(list);
    }
}
